import request from '@/utils/request.js'
import {ref} from 'vue'
//添加学生
export const StudentAddService = (studentData) => {
    return request.post('/student', studentData)
}

//修改学生
export const StudentUpdateService = (studentData) => {
    return request.put('/student', studentData)
}

//删除学生
export const StudentDeleteService = (id) => {
    console.log(id)
    return request.delete('/student?id=' + id)
}


//搜索获取学生信息
export const StudentListBySearchService = (input,select,currentPage,pageSize) =>{
    return request.get('/student/search', {
        params: {
            input: input,
            select: select,
            page: currentPage,
            size: pageSize
        }
    })
}

export const StudentListAllSerivce = () =>{
    return request.get('/student/all')
}


//提供登录接口的函数
export const studentLoginService = async (loginData) => {
    const studentData = ref({
        studentName:loginData.adminName,
        studentPassword:loginData.adminPassword,
    })
    console.log(studentData.value)
    const response = await request.post('/student/login', studentData.value);
    const jwtToken = response.data;
    localStorage.setItem('studentJwtToken', jwtToken);
    return response;
}

//重置密码
export const studentForgetPassService =(phone, pass, verify) => {
    console.log(phone, pass, verify)
    return request.put(`/student/repass?phone=${phone}&pass=${pass}&verify=${verify}`);
}

//修改密码
export const UpdatePasswordService = (userData) => {
    return request.put('/student/password', userData)
}


//搜索学生老师信息
export const StudentListBySearchTeacherService = (input,select,teacherId,currentPage,pageSize) =>{
    return request.get('/student/searchTeacher', {
        params: {
            input: input,
            select: select,
            teacherId:teacherId,
            page: currentPage,
            size: pageSize
        }
    })
}

export const fetchStudentsByMainClass =(id) =>{
    return request.get('/student/fetch?id='+id)
}
